package com.jy.shorturl.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jy.shorturl.dao.ShortUrlDao;

@Component
public class ShortString {
	
	@Autowired
	private ShortUrlDao sud;
	
	public static char bwords[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',  
            'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',  
            'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',  
            'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',  
            'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',  
            '9' };  
	/*public static void main(String[] args) {
        per(new char[4], bwords, 4-1);  
	}*/
		
	/**
	 * 
	 * @param buf 生成字符串的字符数组长度
	 * @param len 下标最大长度
	 */
	 public  void per(char[] buf,int len){  
	     StringBuffer shortUrl = new StringBuffer();   
		 if(len == -1){  
	            for(int i=buf.length-1; i>=0; --i)
            	shortUrl = shortUrl.append(buf[i]);	
	            sud.insertShortUrl(shortUrl.toString()); 
	            return;  
	        }  
	        for(int i=0; i<bwords.length; i++){  
	            buf[len] = bwords[i];  
	            per(buf,len-1);  
	        }  
	    }  
}
